 package com.zu.commu.auto1_0.protocol.call20Date;

 import com.zu.commu.auto1_0.DataType1_0;
 import com.zu.commu.auto1_0.protocol.CheckData;
 import com.zu.commu.auto1_0.protocol.Util;
 import com.zu.commu.exception.CommuException;
 
 public class Call20DateProtocol
 {
   public byte[] remoteData(String meterNo, String whatDate)
     throws Exception
   {
     byte[] buf = new byte[15];
     buf[0] = 104;
     buf[1] = 9;
     buf[2] = 9;
     buf[3] = 104;
     try {
       Util u = new Util();
       byte[] b = u.hex2Byte(meterNo);
       for (int i = 0; i < b.length; i++)
         buf[(4 + i)] = b[i];
     }
     catch (Exception e) {
       throw new CommuException().setMessage(
         "测控器地址号不合法！" + e.getMessage(), null);
     }
     try {
       int wd = Integer.parseInt(whatDate);
       if ((wd < 0) || (wd > 20)) {
         throw new CommuException().setMessage("所请求的天数据不合法！其为" + 
           whatDate, null);
       }
       buf[10] = (byte)wd;
     } catch (Exception e) {
       throw new CommuException().setMessage(
         "所请求的天数据不合法！" + e.getMessage(), null);
     }
     buf[10] = 64;
     buf[11] = (byte)DataType1_0.REPORT20DATEDATA.toInt();
     try {
       int wd = Integer.parseInt(whatDate);
       if ((wd < 0) || (wd > 20)) {
         throw new CommuException().setMessage("所请求的天数据不合法！其为" + 
           whatDate, null);
       }
       buf[12] = (byte)wd;
     } catch (Exception e) {
       throw new CommuException().setMessage(
         "所请求的天数据不合法！" + e.getMessage(), null);
     }
     buf[13] = new CheckData().getCrcCheck(buf, 4, 12);
     buf[14] = 22;
 
     return buf;
   }
 }